<template>
  <div id="home">
    <div>
      <div class="header">
        <van-swipe class="my-swipe" :autoplay="3000" indicator-color="white">
          <van-swipe-item v-for="item in banner" :key="item.id">
            <a :href="item.url">
              <img :src="apiConfig.imgUrl + item.img" alt="" />
            </a>
          </van-swipe-item>
        </van-swipe>
      </div>
      <div class="content">
      <!-- <div class="data">
          <div class="title">数据统计</div>
          <div class="main">
            <ul class="clearfix">
              <li>
                <div @click="$router.push(`patient`)">
                  <p>现存患者</p>
                  <h2>{{ dataStatistics.huanzhe }}</h2>
                </div>
              </li>
              <li>
                <div>
                  <p>本月提交复康日志人数</p>
                  <h2>{{ dataStatistics.logs }}</h2>
                </div>
              </li>
            </ul>
          </div>
        </div> -->

        <div class="data">
          <div class="patient row">
            <div class="top">
              <img src="@/assets/images/index_hz.png" alt="">
              <p class="myPatient">我的患者</p>
            </div>
            <div class="mind">
              <p class="number">{{dataStatistics.huanzhe}}</p>
              <p class="myTitle">我的管理人数</p>
            </div>
            <div class="look" @click="$router.push(`/hospitalList`)">
              <span>查看</span>
              <van-icon name="arrow" />
            </div>
          </div>
          <div class="doctor row">
            <div class="top">
              <img v-if="yslist.img !== '' && yslist.img !== null" :src="yslist.img" alt="">
              <img v-else src="@/assets/images/doctor_a.png" alt="">
              <p class="myPatient">我的医生</p>
            </div>
            <div class="mind">
              <div class="label_box">
                <p class="number">{{yslist.name}}</p>
                <ul>
                  <li>{{yslist.section}}</li>
                </ul>
              </div>
              <p class="myTitle">{{yslist.company}}</p>
            </div>
            <div class="look" @click="$router.push(`/hospital`)">
              <span>查看</span>
              <van-icon name="arrow" />
            </div>
          </div>
        </div>
      
        <div class="msg">
          <div class="title">消息提醒</div>
          <div class="main">
            <ul>
              <li v-for="(item,index) in massage" :key="index"  @click="toNext(item)">
                <div class="li" v-if="item.cid == 1 || item.cid == 8"> 
                  <van-row type="flex" justify="space-between" align="center">
                    <van-col span="2">
                      <img  v-if="item.cid == 1" src="@/assets/images/doctor202007171725 _106.png" alt=""/>
                      <img v-if="item.cid == 8" src="@/assets/images/doctor202007171725 _108.png" alt=""/>
                      </van-col>
                    <van-col span="16" class="content">
                      <p class="title">{{ item.title }}：</p>
                      <p  v-if="item.cid == 1" class="info"> 您的患者<span style="color:red"> {{item.fsname}} </span>提交了一份复康日志</p>
                      <p  v-if="item.cid == 8" class="info"> 您新增一名患者<span style="color:red"> {{item.hzname}} </span>立即查看</p>
                    </van-col>
                    <van-col span="6">
                      <span class="date">{{ item.created }}</span>
                    </van-col>
                  </van-row>
                </div>
              </li>
              <!-- <li v-for="item in massage" :key="item.id"  @click="toNext(item)">
                <div class="li" v-if="item.cid == 8"> 
                  <van-row type="flex" justify="space-between" align="center">
                    <van-col span="2">
                      <img src="@/assets/images/doctor202007171725 _108.png" alt=""
                    /></van-col>
                    <van-col span="16" class="content">
                      <p class="title">{{ item.title }}：</p>
                      <p class="info"> 您新增一名患者<span style="color:red"> {{item.fsname}} </span>立即查看</p>
                    </van-col>
                    <van-col span="6">
                      <span class="date">{{ item.created }}</span>
                    </van-col>
                  </van-row>
                </div>
              </li> -->
              <li class="no" v-if="massage.length === 0">
                暂无数据
              </li>
            </ul>
          </div>
        </div>
      </div>
    </div>
    <!-- <div class="del" @click="del">清除缓存</div> -->
    <div class="save checkbox" v-show="xieyi==0">
      <van-popup v-model="ruleShow" class="popup" :close-on-click-overlay="false">
        <div>
          <p class="title">服务条款</p>
          <div class="content tiaokuan" v-html="tiaokuan">

          </div>
        </div>
        <div class="btnBox">
            <van-button round block size="small" type="info" @click="agree" >同意并接受</van-button>
        </div>
      </van-popup>
    </div>
  </div>
  
</template>

<script>
import { home,xieyi } from "@/apis/home";
import { exitlogin }  from "@/apis/login"
import apiConfig from '../../../config/api.config'
export default {
  name: "home",
  data() {
    return {
      apiConfig,
      xieyi:0,
      tiaokuan:'',
      banner: [],
      dataStatistics: {},
      massage: [],
      yslist:[],
      domain:null,
      ruleShow:false,
    };
  },
  methods: {
    LoadHome() {
      home().then(res => {
       if(res.codes == 200){
          this.banner = res.data.banner;
          this.dataStatistics = res.data.tongji;
          this.massage = res.data.tixing;
          this.yslist = res.data.yslist
          this.xieyi = res.data.xieyi;
          this.tiaokuan = res.data.tiaokuan
          localStorage.setItem('tiaokuan',res.data.tiaokuan)
          if(sessionStorage.getItem('webUrl') && sessionStorage.getItem('webUrl') !=="/" && sessionStorage.getItem('webUrl') !== null){
            this.$router.push(sessionStorage.getItem('webUrl'))
            sessionStorage.removeItem('webUrl')
          }
          if(res.data.xieyi == 1){
            this.ruleShow = false
          }else{
            this.ruleShow = true
          }
       }
      })
      .catch((err) => {
        if(err.codes == "404") {
          exitlogin()
          .then(res => {
            if(res.codes == '200'){
              localStorage.clear()
              sessionStorage.clear()
              window.location.href =this.apiConfig.baseUrl + '/adviser?domain=' + this.domain
            }
          })
          .catch(err => {
            this.$toast(err.msg);
          });
        }else if(!err.msg) {
          this.$toast("网络错误");
        }else{
          this.$toast(err.msg);
        }
      });
    },
    // 同意并继续协议
    agree() {
      this.ruleShow = false
      xieyi()
      .then(res => {
        // this.hztype=true;
        this.xieyi = 1
      })
      .catch(err => {

      })
    },
    toNext(item) {
      console.log(item)
      if(item.cid == 1){
       if(item.infoid >0 && item.infoid !== "")  {
          if(item.yemian !== null){
            this.$router.push(`/HealthLogDetails/${item.infoid}`)
          }else{
            this.$router.push(`/logDetails/${item.infoid}`)
          }
       }else{
         this.$router.push(`/journalIndex/`)
       }
      }
      if(item.cid == 8){
        this.$router.push(`/detail/${item.infoid}`)
      }
      
    },
    del() {
      localStorage.clear();
      sessionStorage.clear();
    }
  },
  mounted() {
    this.LoadHome();
  },
  created() {
    localStorage.removeItem('adviserId')
    this.domain = sessionStorage.getItem('domain')
  }
};
</script>

<style lang="less">
#home {
  .del{
    width: 80px;
    padding:5px 10px;
    border-radius: 4px;
    text-align: center;
    color:#fff;
    background: chartreuse;
    position: absolute;
    bottom:100px;
    left: 15px;
  }
  text-align: left;
  padding-bottom: 40px;
  .header {
    // height: 192px;
    .my-swipe .van-swipe-item {
      color: #fff;
      font-size: 20px;
      height: 192px;
      line-height: 192px;
      text-align: center;
      background-color: #39a9ed;
      a {
        display: inline-block;
        width: 100%;
        height: 192px;
        img {
          width: 100%;
          height: 192px;
        }
      }
    }
  }

  .title {
    font-size: 20px;
    color: rgba(64, 64, 64, 1);
    line-height: 20px;
    padding-left: 5px;
    margin-bottom: 20px;
    font-weight: bold;
  }
  .content {  
    margin: 15px;
    // .data {
    //   .main {
    //     background-color: #fff;
    //     box-shadow: 0px 0px 8px 0px rgba(229, 229, 229, 1);
    //     border-radius: 8px;
    //     padding: 30px 0 0 12px;
    //     ul {
        
    //       li {
    //         width: 50%;
    //         float: left;
    //         margin-bottom: 30px;
    //         p {
    //           height: 13px;
    //           font-size: 13px;
    //           color: rgba(64, 64, 64, 1);
    //         }
    //         h2 {
    //           margin-top: 10px;
    //           font-size: 26px;
    //           color: rgba(64, 120, 244, 1);
    //         }
    //       }
    //     }
    //   }
    // }
    .data {
      display: flex;
      justify-content: space-between;
      align-items: center;
      .row{
        width: 168px;
        height: 147px;
        background: #FFFFFF;
        border-radius: 3px;
        .top{
          margin-top: 15px;
          margin-left: 6px;
          display: flex;
          align-items: center;
          img{
            display: block;
            width: 40px;
            height: 40px;
            border-radius: 50%;
            margin-right: 8px;
          }
          p {
            font-size: 14px;
            font-weight: 400;
            color: #999999;
            line-height: 18px;
          }
        }
        .mind{
          padding-left: 15px;
          margin-top: 5px;
            .number{
              font-size: 22px;
              font-weight: 600;
              color: #404040;
              line-height: 20px;
            }
            .myTitle{
              margin-top: 10px;
              font-size: 14px;
              font-weight: 400;
              color: #999999;
              line-height: 18px;
              overflow: hidden;
              text-overflow: ellipsis;
              white-space: nowrap;
            }
        }
        .look{ 
          margin-top: 16px;
          padding-left: 15px;  
          font-size: 12px;
          font-weight: 400;
          color: #6791FA;
          line-height: 12px;
          display: flex;
          align-items: center;
          span{
            margin-right: 5px;
          }
        }
      }
      .doctor{
       
        .label_box{
          display: flex;
          align-items: center;
          .number{
            font-size: 16px;
          }
          ul{
            margin-left: 8px;
            li{
              display: inline-block;
              padding: 1px 6px;
              border: 1px solid #4078F4;
              border-radius: 4px;
              font-size: 10px;
              color:#4078F4 ;
            }
          }
        }
      }
    }
    .msg {
      margin-top: 30px;
       .main::-webkit-scrollbar {
          display: none;
          }
      .main {
        max-height: 190px;
        overflow-x: hidden;
        overflow-y: scroll;
        background-color: #fff;
        box-shadow: 0px 0px 8px 0px rgba(229, 229, 229, 1);
        border-radius: 8px;
        padding: 0 12px;
       
        ul {
          .no {
            text-align: center;
            font-size: 15px;
          }
          .li {
            height: 80px;
            line-height: 80px;
            padding-top: 10px;
            position: relative;
            border-bottom: 1px solid rgba(245, 245, 245, 1);
            div{
              position: relative;
            }
            .van-row--align-center{
              align-items: flex-start;
            }
            img {
              position: absolute;
              top: 0;
              display: inline-block;
              vertical-align: sub;
              width: 20px;
              height: 20px;
            }
            &:last-child {
              border: 0;
            }
            .van-row {
              height: 60px;
              line-height: 60px;
            }
            .content {
              margin: 0;
              width: 300px;
             display: flex;
             flex-direction: column;
              overflow: hidden;
              text-overflow: ellipsis;
              .title {
                font-size: 15px;
                line-height: 20px;
                margin-bottom: 0;
                padding-left:0 ;
              }
              .info {
                font-size: 15px;
                line-height: 20px;
                overflow: hidden;
                display: -webkit-box;
                -webkit-line-clamp: 2;
                -webkit-box-orient: vertical;
                
              }
            }
            .date {
              float: right;
              margin-right: 10px;
              font-size: 13px;
              color: rgba(153, 153, 153, 1);
            }
          }
        }
      }
    }
  }
  // 协议条款
   .checkbox {
    font-size: 12px;
    .popup {
      width: 90vw;
      height: 70%;
      padding: 60px 15px 60px 5px;
      border-radius: 15px;
      overflow: hidden;
      div::-webkit-scrollbar {
        display:none
      }
      div{
        width: 98%;
        height: 97%;
        // overflow: hidden;

        .title{
          width: 90vw;
          font-size: 18px;
          font-weight: bold;
          text-align: center;
          position: absolute;
          top: 20px;
          left: 0vw;
        }
        .content{
          line-height: 16px;
          font-size: 12px;
          color: #000;
          overflow-y:scroll;

        }
      }
      .btnBox{
        position: absolute;
        width: 60%;
        height: 80px;
        bottom: -30px;
        left: 20%;
      }
    }

  }
  .save {
    background-color: #fff;
    padding: 30px 20px;
    margin: 16px auto;
    text-align: left;
    .code {
      margin-bottom: 15px;
      font-size: 16px;
      font-weight: 500;
      i {
        display: inline-block;
        width: 13px;
        height: 13px;
        border-radius: 50%;
        background-color: #fa5b57;
      }
    }
  }
}
</style>
